package com.example.testrxjava.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.support.v4.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.testrxjava.util.TransitionHelper;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 项目名称：TestRxjava
 *
 * @Author 郭迎辉
 * Create by 10:07 on 2019/4/18.
 * Describe:
 */
public abstract class BaseFragment extends Fragment {
    public Activity activity;
    private View view;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity=getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if(view==null){
            view=initView();
        }
        ButterKnife.bind(this,view);
        return view;
    }
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public void transitionTo(Intent i) {
        final Pair<View, String>[] pairs = TransitionHelper.createSafeTransitionParticipants(getActivity(), true);
        ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), pairs);
        startActivity(i, transitionActivityOptions.toBundle());
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
                initData();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    protected abstract void initData();

    protected abstract View initView();

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
